package com.second.app.thread.p_c_test;

/**
 * @author gyz
 * @date 2021/1/25 17:31
 */
public class Consumer {
    private String lock;

    public Consumer(String lock) {
        this.lock = lock;
    }

    public void getValue() {
        try {
            synchronized (lock) {
                //线程消费,发现value值为空，就让此线程休息
                if (ValueObject.getValue().equals("")) {
                    lock.wait();
                }
                //否则，就去消费值
                System.out.println(Thread.currentThread().getName() + ":消费的值" + ValueObject.getValue());
                //消费完成置空,通知生产线程继续生产
                ValueObject.setValue("");
                lock.notify();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
